Vue.component('Update', {
	template: `
		<el-dialog title="修改" width="600px" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm" append-to-body>
			<el-form :size="size" ref="form" :model="form" :rules="rules" :label-width=" ismobile()?'90px':'16%'">
				<el-row >
					<el-col :span="24">
						<el-form-item label="添加时间" prop="add_time">
							<el-date-picker value-format="yyyy-MM-dd HH:mm:ss" type="datetime" v-model="form.add_time" clearable placeholder="请输入添加时间"></el-date-picker>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="资源类型" prop="status">
							<el-radio-group v-model="form.status">
								<el-radio :label="1">新</el-radio>
								<el-radio :label="2">旧</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="联系人" prop="name">
							<el-input  v-model="form.name" autoComplete="off" clearable  placeholder="请输入联系人"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="手机号码" prop="mobile">
							<el-input  v-model="form.mobile" autoComplete="off" clearable  placeholder="请输入手机号码"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="资源描述" prop="info">
							<el-input  v-model="form.info" autoComplete="off" clearable  placeholder="请输入资源描述"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="租金转让" prop="sell">
							<el-input  v-model="form.sell" autoComplete="off" clearable  placeholder="请输入租金转让"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="面积" prop="area">
							<el-input  v-model="form.area" autoComplete="off" clearable  placeholder="请输入面积"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="楼层" prop="floor">
							<el-input  v-model="form.floor" autoComplete="off" clearable  placeholder="请输入楼层"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="区域" prop="regoin">
							<el-input  v-model="form.regoin" autoComplete="off" clearable  placeholder="请输入区域"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="联系地址" prop="contact_address">
							<el-input  v-model="form.contact_address" autoComplete="off" clearable  placeholder="请输入联系地址"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="经营类型" prop="type">
							<el-select style="width:100%" v-model="form.type" filterable clearable placeholder="请选择经营类型">
								<el-option key="0" label="餐饮美食" :value="餐饮美食"></el-option>
								<el-option key="1" label="美容美发" :value="美容美发"></el-option>
								<el-option key="2" label="服饰鞋包" :value="服饰鞋包"></el-option>
								<el-option key="3" label="休闲娱乐" :value="休闲娱乐"></el-option>
								<el-option key="4" label="百货超市" :value="百货超市"></el-option>
								<el-option key="5" label="生活服务" :value="生活服务"></el-option>
								<el-option key="6" label="电器通讯" :value="电器通讯"></el-option>
								<el-option key="7" label="汽修美容" :value="汽修美容"></el-option>
								<el-option key="8" label="医疗器械" :value="医疗器械"></el-option>
								<el-option key="9" label="家居建材" :value="家居建材"></el-option>
								<el-option key="10" label="教育培训" :value="教育培训"></el-option>
								<el-option key="11" label="酒店宾馆" :value="酒店宾馆"></el-option>
								<el-option key="12" label="其他" :value="其他"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="物业类型" prop="property_type">
							<el-input  v-model="form.property_type" autoComplete="off" clearable  placeholder="请输入物业类型"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="剩余租期" prop="lease_term">
							<el-input  v-model="form.lease_term" autoComplete="off" clearable  placeholder="请输入剩余租期"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="房屋规格" prop="specs">
							<el-input  v-model="form.specs" autoComplete="off" clearable  placeholder="请输入房屋规格"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="押付金" prop="deposit">
							<el-input  v-model="form.deposit" autoComplete="off" clearable  placeholder="请输入押付金"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="点击" prop="click">
							<el-input  v-model="form.click" autoComplete="off" clearable  placeholder="请输入点击"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="跟单详情" prop="documentary_info">
							<el-input  type="textarea" autoComplete="off" v-model="form.documentary_info"  :autosize="{ minRows: 2, maxRows: 4}" clearable placeholder="请输入跟单详情"/>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="跟单方式" prop="documentary_mothod">
							<el-select style="width:100%" v-model="form.documentary_mothod" filterable clearable placeholder="请选择跟单方式">
								<el-option key="0" label="电话沟通" :value="1"></el-option>
								<el-option key="1" label="微信交流" :value="2"></el-option>
								<el-option key="2" label="QQ/旺旺" :value="3"></el-option>
								<el-option key="3" label="电子邮箱" :value="4"></el-option>
								<el-option key="4" label="上门拜访" :value="5"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="客户类型" prop="connection_type">
							<el-checkbox-group v-model="form.connection_type">
								<el-checkbox key="0" label="1">保护客户</el-checkbox>
								<el-checkbox key="1" label="2">收藏客户</el-checkbox>
							</el-checkbox-group>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="首次资源地址" prop="url">
							<el-input  v-model="form.url" autoComplete="off" clearable  placeholder="请输入首次资源地址"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="进展" prop="evolve">
							<el-select style="width:100%" v-model="form.evolve" filterable clearable placeholder="请选择进展">
								<el-option key="0" label="待访问客户" :value="1"></el-option>
								<el-option key="1" label="考虑客户" :value="2"></el-option>
								<el-option key="2" label="无效客户" :value="3"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="需求类型" prop="need_type">
							<el-input  v-model="form.need_type" autoComplete="off" clearable  placeholder="请输入需求类型"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="微信号" prop="weixin">
							<el-input  v-model="form.weixin" autoComplete="off" clearable  placeholder="请输入微信号"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="电话二维码" prop="img">
							<Upload v-if="show" size="small"  upload_type="1"   rename="2" file_type="image"  :image.sync="form.img"></Upload>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="备注" prop="back">
							<el-input  v-model="form.back" autoComplete="off" clearable  placeholder="请输入备注"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button :size="size" :loading="loading" type="primary" @click="submit" >
					<span v-if="!loading">确 定</span>
					<span v-else>提 交 中...</span>
				</el-button>
				<el-button :size="size" @click="closeForm">取 消</el-button>
			</div>
		</el-dialog>
	`
	,
	components:{
	},
	props: {
		show: {
			type: Boolean,
			default: false
		},
		size: {
			type: String,
			default: 'small'
		},
		info: {
			type: Object,
		},
	},
	data(){
		return {
			form: {
				add_time:'',
				status:1,
				name:'',
				mobile:'等待录入',
				info:'',
				sell:'',
				area:'',
				floor:'',
				regoin:'',
				contact_address:'',
				property_type:'',
				lease_term:'',
				specs:'',
				deposit:'',
				click:'0',
				documentary_info:'',
				connection_type:[],
				url:'',
				evolve:1,
				need_type:'',
				weixin:'',
				img:'',
				back:'',
			},
			loading:false,
			rules: {
				name:[
					{required: true, message: '联系人不能为空', trigger: 'blur'},
				],
				evolve:[
					{required: true, message: '进展不能为空', trigger: 'change'},
				],
			}
		}
	},
	methods: {
		open(){
			this.form = this.info
			this.form.add_time = parseTime(this.form.add_time)
			this.setDefaultVal('connection_type')
		},
		submit(){
			this.$refs['form'].validate(valid => {
				if(valid) {
					this.loading = true
					axios.post(base_url + '/Resource/update',this.form).then(res => {
						if(res.data.status == 200){
							this.$message({message: res.data.msg, type: 'success'})
							this.$emit('refesh_list')
							this.closeForm()
						}else{
							this.loading = false
							this.$message.error(res.data.msg)
						}
					}).catch(()=>{
						this.loading = false
					})
				}
			})
		},
		setDefaultVal(key){
			if(this.form[key] == null || this.form[key] == ''){
				this.form[key] = []
			}
		},
		closeForm(){
			this.$emit('update:show', false)
			this.loading = false
			if (this.$refs['form']!==undefined) {
				this.$refs['form'].resetFields()
			}
		},
	}
})
